package cn.platform.controller;

import cn.platform.request.ClassQueryDTO;
import cn.platform.request.ClazzDTO;
import cn.platform.response.ClassDetailVO;
import cn.platform.response.ClassVO;
import cn.platform.response.PageResult;
import cn.platform.response.Result;
import cn.platform.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/classes")
public class ClazzController {
    @Autowired
    private ClazzService clazzService;

    /**
     * 分页查询班级信息
     * @param classQueryDTO
     * @return
     */
    @GetMapping
    public Result page(ClassQueryDTO classQueryDTO){
        log.info("分页查询班级信息{}",classQueryDTO);
        PageResult<ClassVO> pageResult= clazzService.page(classQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 查看班级详细信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result getClassDetail(@PathVariable String id){
        log.info("查询班级详细信息{}",id);
        ClassDetailVO detail = clazzService.getClassDetail(id);
        return Result.success(detail);
    }

    /**
     * 新增班级信息
     * @param addDTO
     * @return
     */
    @PostMapping
    public Result saveClass(@RequestBody ClazzDTO addDTO){
        log.info("新增班级信息{}",addDTO);
        clazzService.saveClass(addDTO);
        return Result.success();
    }

    /**
     * 更新班级信息
     * @param updateDTO
     * @return
     */
    @PutMapping
    public Result update(@RequestBody ClazzDTO updateDTO){
        log.info("更新班级信息{}",updateDTO);
        clazzService.update(updateDTO);
        return Result.success();
    }

    /**
     * 删除班级信息
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable String id){
        log.info("删除班级{}",id);
        clazzService.delete(id);
        return Result.success();
    }

    @DeleteMapping()
    public Result deleteBatch(@RequestBody List<String> ids){
        log.info("批量删除班级信息{}",ids);
        clazzService.deleteBatch(ids);
        return Result.success();
    }

}
